﻿@model SiteThemeSelectorModel
@using IT.CMS.Web.Models.Common;
@if (Model.AvailableSiteThemes.Count > 1)
{
    using (Ajax.BeginForm("SiteThemeSelected", "Common", null, new AjaxOptions { OnComplete = "onSiteThemeChangedRequestCompleted();" }, new { id = "form-site-theme-selector" }))
    {
        var themes = Model.AvailableSiteThemes.Select(x => new SelectListItem
        {
            Text = x.Title,
            Value = x.Name,
            Selected = x.Name.Equals(Model.CurrentSiteTheme.Name, StringComparison.InvariantCultureIgnoreCase)
        });
    
        @T("SiteTheme")<text>:</text> @Html.DropDownList("themeName", themes, new { @class = "site-theme-list" })
    }
    <script type="text/javascript">
        $(document).ready(function () {
            $("#themeName").change(onSiteThemeChanged);
        });

        function onSiteThemeChanged() {
            $("#form-site-theme-selector").submit();
        }
        function onSiteThemeChangedRequestCompleted() {
            location.reload();
        }
    </script>
}